package pyip.lib.javalearn.aop.dynamicproxy.spring.baseadvice;

import org.springframework.aop.framework.ProxyFactory;

import pyip.lib.javalearn.aop.dynamicproxy.Greeting;
import pyip.lib.javalearn.aop.dynamicproxy.GreetingImpl;

public class Client {

    public static void main(String[] args) {
        ProxyFactory proxyFactory = new ProxyFactory(); // 创建代理工厂
        proxyFactory.setTarget(new GreetingImpl()); // 射入目标类对象
        // proxyFactory.addAdvice(new GreetingBeforeAndAfterAdvice());// 添加Around Advice
        proxyFactory.addAdvice(new GreetingAroundAdvice());
        proxyFactory.addAdvice(new GreetingBeforeAdvice()); // 添加前置增强
        proxyFactory.addAdvice(new GreetingAfterAdvice()); // 添加后置增强

        Greeting greeting = (Greeting) proxyFactory.getProxy(); // 从代理工厂中获取代理
        greeting.sayHello("Jack"); // 调用代理的方法
    }
}